package cn.geminis.data.jpa.filter;

import cn.geminis.data.jpa.QueryPredicateBuilder;
import cn.geminis.data.jpa.entity.Teacher;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.jpa.domain.Specification;

@Getter
@Setter
@Builder
public class TeacherFilter implements Specification<Teacher> {

    private String name;

    @Override
    public Predicate toPredicate(Root<Teacher> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {

        var builder = new QueryPredicateBuilder<>(root, query, criteriaBuilder);
        builder.equal("name", name);

        return builder.build();
    }
}
